package cn.kwq.project_manger.aop;

import cn.kwq.project_manger.pojo.InstituteDic;
import cn.kwq.project_manger.pojo.MajorDic;
import cn.kwq.project_manger.repostitory.InstituteDicRepository;
import cn.kwq.project_manger.repostitory.MajorDicRepository;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * 爬取我校
 * 相关数据到字典表
 */
@Component
public class test {


    @Autowired
    MajorDicRepository majorDicRepository;
    @Autowired
    InstituteDicRepository instituteDicRepository;

    public  void get() throws IOException {
        Document doc = Jsoup
                .parse(
                new File( "D:/CodeSpace/Project/Project_Manger/test.html" )
                        , "utf-8"
                );
        List<InstituteDic> yxs=new ArrayList<>();
        List<MajorDic> zys=new ArrayList<>();
        Element yx = doc.getElementById("yxdm");
        Element zy = doc.getElementById("zydm");

        Elements yoption = yx.select("option");
        Elements zoption = zy.select("option");

        for (Element e:yoption){
            //去掉全部
            String text = e.text();
            if (text.equals("(全部)")){
                continue;
            }
            //裁剪前缀
            String[] split = text.split("-");

            yxs.add(InstituteDic
                    .builder()
                    .instituteName(split[1].replaceAll("\\s*", ""))
                    .build());
        }
        for (Element e:zoption){
            //去掉全部
            String text = e.text();
            if (text.equals("(全部)")){
                continue;
            }
            //裁剪前缀
            String[] split = text.split("-");
            zys.add(MajorDic
                    .builder()
                    .majorName(split[1].replaceAll("\\s*",""))
                    .build());
        }


        System.out.println(zys);;


    }
}

